﻿@model IEnumerable<SheBeiGLXT.Models.Defect>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<div style="text-align:center">
    <form method="get" class="form-inline text-center" style="margin:10px">
        所属设备：@Html.DropDownList("id", null, new { @class = "form-control" })
        缺陷内容：<input type="text" name="Content" class="form-control" placeholder="请输入内容关键字" />
        <input type="submit" value="查询" class="btn btn-primary" />
        @Html.ActionLink("添加", "Create", null, new { @class = "btn btn-primary" })
    </form>
</div>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.DefectType)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DefectState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DealTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Device.DeviceName)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @*缺陷类型*@
                @if (item.DefectType == 1)
                {
                    @:紧急
                }
                else if (item.DefectType == 2)
                {
                    @:重要
                }
                else if (item.DefectType == 3)
                {
                    @:一般
                }
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Content)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @(item.DefectState == 1?"已处理":"未处理")
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.DealTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Device.DeviceName)
            </td>
            <td>
                @Html.ActionLink("处理缺陷", "Edit", new { id = item.DefectID }) |
                @*@Html.ActionLink("Details", "Details", new { id = item.DefectID }) |*@
                @*@Html.ActionLink("Delete", "Delete", new { id=item.DefectID })*@
                <a href="#" data-del="@item.DefectID">删除</a>
            </td>
        </tr>
    }

</table>

@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("您确定要删除id=" + id + "?")) return;
                $.post("@Url.Content("~/Default/Delete")", { id: id }, function (res) {
                    if (res == true) {
                        alert("删除成功！");
                        location.reload();
                    }
                })
            })
        })
    </script>

}

